// var base_url = "http://100.5.12.148:8889/web";
var base_url = "http://localhost:8889/web";
var tophref = top.location.href;
var thishref = location.href;
var username, projectid, projectname;

try{
	username = tophref.split("=")[1].split("#")[0];
	projectid = tophref.split("=")[3].split("#")[0];
	projectname = decodeURI(tophref.split("=")[2].split("#")[0]);
}catch(e){
	if(tophref.indexOf(username) == -1 && tophref.indexOf("login.html") == -1 && tophref.indexOf("addproject.html") == -1) {
		top.location.href = "login.html";
	}
}

//发送请求公用方法
$.ajaxSetup({
	timeout: 3000,
	//请求成功后触发
	success: function(data) {},
	//请求失败遇到异常触发
//	error: function(XMLHttpRequest, status, e) {
//		layui.use(['layer'], function() {
//			layer.msg('请求异常');
//			setTimeout(function() {
//				top.location.href = 'login.html'
//			}, 2 * 1000);
//		});
//	},
	//完成请求后触发。即在success或error触发后触发
	complete: function(XMLHttpRequest, status) {},
	//发送请求前触发
	beforeSend: function(XMLHttpRequest) {
		XMLHttpRequest.setRequestHeader('token', username);
		XMLHttpRequest.setRequestHeader('projectid', projectid);
	},
});

//初始化
$(document).ready(function() {
	if (username == -1 && thishref.indexOf("login.html") == -1) {
		location.href = 'login.html'
		return;
	}
	if (thishref.indexOf("index.html") != -1) {
		if (username == "" || username == null) {
			top.location.href = 'login.html'
		}
		if (username.split("|")[0] != "admin") {
			$('#admin').hide()
		}
		$("#username").append(username.split("|")[0]);
	}

});

function fresh() {
	window.location.reload();
}
